import axios from 'axios';
import nprogress from 'nprogress';
//如果出现进度条没有显示：一定是你忘记了引入样式了
import 'nprogress/nprogress.css';
let requests = axios.create({
  baseURL: '/mock',
  timeout: 5000,
});

requests.interceptors.request.use((confing) => {
  nprogress.start();
  return confing;
});

requests.interceptors.response.use(
  (res) => {
    nprogress.done();
    return res.data;
  },
  (err) => {
    alert('服务器响应数据失败');
  },
);

export default requests;
